package pl.iachoo.ctl.tabory.ui.properties;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;

public class Messages {

	private final static Logger log = Logger.getLogger(Messages.class);

	private final static Locale locale = Locale.getDefault();

	private static ResourceBundle resourceBundle;

	static {
		try {
			resourceBundle = ResourceBundle.getBundle("messages",
					Messages.locale);
		} catch (Exception e) {
			resourceBundle = null;
			log.error(e.getMessage(), e);
		}
	}

	public static String getString(final String key) {
		try {
			return resourceBundle.getString(key.trim());
		} catch (final MissingResourceException e) {
			Messages.log.error(e.getMessage(), e);
			return '!' + key + '!';
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			return '!' + key + '!';
		}
	}

}
